#include "stdafx.h"
#include "MainMenuPainter.h"
#include "IResCfg.h"
#include "CMSGInforCon.h"
#include "CZoomBmpBtn.h"
#include "CHeartRateSetting.h"


CHeartRateSetting::CHeartRateSetting(HWND hWnd):CMessageBoxCon(hWnd)
{
	
}

CHeartRateSetting::~CHeartRateSetting(void)
{
}

void  CHeartRateSetting::ShowResult(BOOL bShow)
{

  	CText* pText=NULL; 
	CBmpBtn* pBtn = NULL;
	CPicture *pPic=NULL;

	if (bShow)
	{
    pPic=(CPicture*)ControlFromID(CMD_MSG_GSHEART_MIN_NUM_BK);
	 pPic->Show(FALSE);
    pPic=(CPicture*)ControlFromID(CMD_MSG_GSHEART_MAX_NUM_BK);
	pPic->Show(FALSE);
    pBtn=(CZoomBmpBtn*)ControlFromID(CMD_MSG_GSHEART_MIN_DOWN);
	pBtn->Show(FALSE);
	pBtn=(CZoomBmpBtn*)ControlFromID(CMD_MSG_GSHEART_MIN_UP);
	pBtn->Show(FALSE);
	pBtn=(CZoomBmpBtn*)ControlFromID(CMD_MSG_GSHEART_MAX_DOWN);
	pBtn->Show(FALSE);
	pBtn=(CZoomBmpBtn*)ControlFromID(CMD_MSG_GSHEART_MAX_UP);
	pBtn->Show(FALSE);
	m_pNumberMINCtrl->Show(FALSE);
	m_pNumberMAXCtrl->Show(FALSE);


	
	}










}


BOOL CHeartRateSetting::InitControls(DWORD dwData)
{
	//message box
	LANGUAGE_DECLARE;
	FONT_DECLARE;

	HBITMAP hBitmap = NULL;

	CIResCfg ResCon;
	if(!ResCon.Init(L"SetHeartRate.xml"))
	{
		//g_App.ShowMsgBox(CMD_MSGBOX_OK,L"",LAN_GETTEXT(Msg_ResError));
		return FALSE;
	}

	m_nAniType  = ResCon.GetAniType();
	m_nExitAniType=ResCon.GetExitAniType();
	m_nAniSpeed = ResCon.GetAniSpeed();
	SetRect(ResCon.GetRect());
	BOOL bFromDll = ResCon.IsResFromDll();
	BtnParam btnInfo;

	hBitmap = CUtil::LoadBitmapEx(ResCon.GetImage(),bFromDll);


	BatTimePicParam picInfo;
	ResCon.GetBatTimePicParam(picInfo,L"Pic_Bkgnd");
	CPicture *pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC, L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);

	TextParam txtInfo;
	CText* pText=NULL; 


	//{
	ResCon.GetTextParam(txtInfo,L"Title");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(MSG_HS_FITSTREAM_TITLE),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
	//}


	ResCon.GetTextParam(txtInfo,L"Text_Age");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(GS_AGE),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);

	ResCon.GetTextParam(txtInfo,L"Text_Weight");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(GS_WEIGHT),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);



	CCheckBtn* pCheckBtn=NULL;







	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Icon_male");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_ICON_MALE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(true);


	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Icon_fmale");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_ICON_FMALE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(true);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Icon_fire");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_ICON_FIRE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(true);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Icon_heart");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_ICON_HEART));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(true);

	ResCon.GetBtnParam(btnInfo,L"CheckBtn_Icon_cycle");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_ICON_CYCLE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(true);

	


	ResCon.GetBtnParam(btnInfo,L"CheckBtn_male");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_MALE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(true);
	ResCon.GetBtnParam(btnInfo,L"CheckBtn_fmale");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_FMALE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(true);
	ResCon.GetBtnParam(btnInfo,L"CheckBtn_cycle");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_CYCLE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(false);
	ResCon.GetBtnParam(btnInfo,L"CheckBtn_fire");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_FIRE));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(false);


	ResCon.GetBtnParam(btnInfo,L"CheckBtn_heart");
	pCheckBtn = (CCheckBtn*)this->AddControl(new CCheckBtn(SBS_RECT, L"", btnInfo.m_rc, CMD_MSG_GSHEART_HEART));
	ResCon.SetBtnParam(pCheckBtn,btnInfo);
	pCheckBtn->SetChecked(true);

	
	
	ResCon.GetBatTimePicParam(picInfo,L"Icon_AgeBK");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC, L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);


	ResCon.GetBatTimePicParam(picInfo,L"Icon_WeightBK");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC, L"",picInfo.m_rc, CMD_MSGBOX_PIC));
	ResCon.SetPicParam(pPic,picInfo);


	ResCon.GetBatTimePicParam(picInfo,L"Icon_MinxBK");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC, L"",picInfo.m_rc, CMD_MSG_GSHEART_MIN_NUM_BK));
	ResCon.SetPicParam(pPic,picInfo);


	ResCon.GetBatTimePicParam(picInfo,L"Icon_MaxBK");
	pPic = (CPicture*)AddControl(new CPicture(SWS_STATIC, L"",picInfo.m_rc, CMD_MSG_GSHEART_MAX_NUM_BK));
	ResCon.SetPicParam(pPic,picInfo);


	
	CZoomBmpBtn* pBtn = NULL;

	ResCon.GetBtnParam(btnInfo,L"Btn_No");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,LAN_GETTEXT(MSG_CANCLE),btnInfo.m_rc, CMD_MSG_GSHEART_CANCLE));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"Btn_Yes");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,LAN_GETTEXT(MSG_OK),btnInfo.m_rc, CMD_MSG_GSHEART_OK));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"HeartRate_Age_BTN_LEFT");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_AGE_LEFT));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"HeartRate_Age_BTN_RIGHT");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_AGE_RIGHT));
	ResCon.SetBtnParam(pBtn,btnInfo);




	ResCon.GetBtnParam(btnInfo,L"HeartRate_Weight_BTN_LEFT");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_WEIGHT_LEFT));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"HeartRate_Weight_BTN_RIGHT");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_WEIGHT_RIGHT));
	ResCon.SetBtnParam(pBtn,btnInfo);



	ResCon.GetBtnParam(btnInfo,L"HeartRatet_MIN_BTN_DOWN");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_MIN_DOWN));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"HeartRatet_MIN_BTN_UP");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_MIN_UP));
	ResCon.SetBtnParam(pBtn,btnInfo);





	ResCon.GetBtnParam(btnInfo,L"HeartRatet_MAX_BTN_UP");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_MAX_UP));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"HeartRatet_MAX_BTN_DOWN");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_MAX_DOWN));
	ResCon.SetBtnParam(pBtn,btnInfo);


	ResCon.GetBtnParam(btnInfo,L"Btn_KG");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_KG));
	ResCon.SetBtnParam(pBtn,btnInfo);

	ResCon.GetBtnParam(btnInfo,L"Btn_Lbs");
	pBtn = (CZoomBmpBtn*)AddControl(new CZoomBmpBtn(SBS_RECT,L"",btnInfo.m_rc, CMD_MSG_GSHEART_LBS));
	ResCon.SetBtnParam(pBtn,btnInfo);



	IBmpNumInfo btpInfo;
	ResCon.LoadIBmpNumParam(btpInfo,L"Count_Age_Ctrl");
    m_pNumberAgeCtrl = (CNumberCtrl*)AddControl(new CNumberCtrl(SBS_RECT, L"", btpInfo.m_rc, CMD_MSG_GSHEART_AGE_NUM));
	ResCon.SetBmpNumParam(m_pNumberAgeCtrl,btpInfo);





	ResCon.LoadIBmpNumParam(btpInfo,L"Count_Heart_Ctrl");
	m_pNumberWeightCtrl = (CNumberCtrl*)AddControl(new CNumberCtrl(SBS_RECT, L"", btpInfo.m_rc, CMD_MSG_GSHEART_WEIGHT_NUM));
	ResCon.SetBmpNumParam(m_pNumberWeightCtrl,btpInfo);




	
	ResCon.LoadIBmpNumParam(btpInfo,L"Count_MIN_Ctrl");
	 m_pNumberMINCtrl = (CNumberCtrl*)AddControl(new CNumberCtrl(SBS_RECT, L"", btpInfo.m_rc, CMD_MSG_GSHEART_MIN_NUM));
	ResCon.SetBmpNumParam(m_pNumberMINCtrl,btpInfo);



	ResCon.LoadIBmpNumParam(btpInfo,L"Count_MAX_Ctrl");
    m_pNumberMAXCtrl = (CNumberCtrl*)AddControl(new CNumberCtrl(SBS_RECT, L"", btpInfo.m_rc, CMD_MSG_GSHEART_MAX_NUM));
	ResCon.SetBmpNumParam(m_pNumberMAXCtrl,btpInfo);

	

	ResCon.GetTextParam(txtInfo,L"Text_Age");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(GS_AGE),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);

	ResCon.GetTextParam(txtInfo,L"Text_Weight");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(GS_WEIGHT),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);



	ResCon.GetTextParam(txtInfo,L"Conclusion_Rate");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(GS_AGE),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
	pText->Show(FALSE);

	ResCon.GetTextParam(txtInfo,L"Conclusion_Range");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(GS_WEIGHT),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
   pText->Show(FALSE);


	ResCon.GetTextParam(txtInfo,L"Conclusion_Rate_Title");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(GS_AGE),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
	pText->Show(FALSE);

	ResCon.GetTextParam(txtInfo,L"Conclusion_Range_Title");
	pText = (CText*)AddControl(new CText(SWS_STATIC,LAN_GETTEXT(GS_WEIGHT),txtInfo.m_rc, CMD_MSG_FITSTREAM_TEXT));
	ResCon.SetTextParam(pText,txtInfo);
	pText->Show(FALSE);


	//SetPainter(new CMainMenuPainter());
	return true;
}

void  CHeartRateSetting::OnCommand(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
{
	CCheckBtn * pBtn=NULL;
	switch (wParam)
	{
	case CMD_MSG_GSHEART_MALE:
		{

			for(int i=CMD_MSG_GSHEART_MALE;i<CMD_MSG_GSHEART_MALE+2;i++)
			{
				pBtn=  (CCheckBtn *)ControlFromID(i);
				if (i==CMD_MSG_GSHEART_MALE)
				{
					pBtn->SetChecked(true);
					continue;
				}
				pBtn->SetChecked(false);
			}

			for(int i=CMD_MSG_GSHEART_ICON_MALE;i<CMD_MSG_GSHEART_ICON_MALE+2;i++)
			{
				pBtn=  (CCheckBtn *)ControlFromID(i);
				if (i==CMD_MSG_GSHEART_ICON_MALE)
				{
					pBtn->SetChecked(false);
					continue;
				}
				pBtn->SetChecked(true);
			}

		}
		break;
	case  CMD_MSG_GSHEART_FMALE:
		for(int i=CMD_MSG_GSHEART_MALE;i<CMD_MSG_GSHEART_MALE+2;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_GSHEART_FMALE)
			{
				pBtn->SetChecked(true);
				continue;
			}
			pBtn->SetChecked(false);
		}

		for(int i=CMD_MSG_GSHEART_ICON_MALE;i<CMD_MSG_GSHEART_ICON_MALE+2;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_GSHEART_ICON_FMALE)
			{
				pBtn->SetChecked(false);
				continue;
			}
			pBtn->SetChecked(true);
		}
		break;
	case  CMD_MSG_GSHEART_FIRE:
		for(int i=CMD_MSG_GSHEART_FIRE;i<CMD_MSG_GSHEART_FIRE+3;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_GSHEART_FIRE)
			{
				pBtn->SetChecked(true);
				continue;
			}
			pBtn->SetChecked(false);
		}

		for(int i=CMD_MSG_GSHEART_ICON_FIRE;i<CMD_MSG_GSHEART_ICON_FIRE+3;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_GSHEART_ICON_FIRE)
			{
				pBtn->SetChecked(false);
				continue;
			}
			pBtn->SetChecked(true);
		}
		break;
	case CMD_MSG_GSHEART_HEART:
		for(int i=CMD_MSG_GSHEART_FIRE;i<CMD_MSG_GSHEART_FIRE+3;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_GSHEART_HEART)
			{
				pBtn->SetChecked(true);
				continue;
			}
			pBtn->SetChecked(false);
		}

		for(int i=CMD_MSG_GSHEART_ICON_FIRE;i<CMD_MSG_GSHEART_ICON_FIRE+3;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_GSHEART_ICON_HEART)
			{
				pBtn->SetChecked(false);
				continue;
			}
			pBtn->SetChecked(true);
		}
		break;
	case CMD_MSG_GSHEART_CYCLE:
		{
			for(int i=CMD_MSG_GSHEART_FIRE;i<CMD_MSG_GSHEART_FIRE+3;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_GSHEART_CYCLE)
			{
				pBtn->SetChecked(true);
				continue;
			}
			pBtn->SetChecked(false);
		}

		for(int i=CMD_MSG_GSHEART_ICON_FIRE;i<CMD_MSG_GSHEART_ICON_FIRE+3;i++)
		{
			pBtn=  (CCheckBtn *)ControlFromID(i);
			if (i==CMD_MSG_GSHEART_ICON_CYCLE)
			{
				pBtn->SetChecked(false);
				continue;
			}
			pBtn->SetChecked(true);
		}
		ShowResult(true);

		}
		break;

	case CMD_MSG_GSHEART_AGE_LEFT:
		{
			int val=m_pNumberAgeCtrl->GetValue();
			m_pNumberAgeCtrl->SetValue(val-1);
		}
		break;
	case  CMD_MSG_GSHEART_AGE_RIGHT:
		{
			int val=m_pNumberAgeCtrl->GetValue();
			m_pNumberAgeCtrl->SetValue(val+1);
		}
	
		break;
	case CMD_MSG_GSHEART_WEIGHT_LEFT:
		{
			int val=m_pNumberWeightCtrl->GetValue();
			m_pNumberWeightCtrl->SetValue(val-1);
		}
		break;
	case CMD_MSG_GSHEART_WEIGHT_RIGHT:
		{
			int val=m_pNumberWeightCtrl->GetValue();
			m_pNumberWeightCtrl->SetValue(val+1);
		}
		break;
	case  CMD_MSG_GSHEART_MIN_DOWN:
		{
			int val=m_pNumberMINCtrl->GetValue();
			m_pNumberMINCtrl->SetValue(val-1);
		}
		break;
	case CMD_MSG_GSHEART_MIN_UP:
		{
			int val=m_pNumberMINCtrl->GetValue();
			m_pNumberMINCtrl->SetValue(val+1);
		}
		break;
	case  CMD_MSG_GSHEART_MAX_DOWN:
		{
			int val=m_pNumberMAXCtrl->GetValue();
			m_pNumberMAXCtrl->SetValue(val-1);
		}
		break;
	case  CMD_MSG_GSHEART_MAX_UP:
		{
			int val=m_pNumberMAXCtrl->GetValue();
			m_pNumberMAXCtrl->SetValue(val+1);
		}
		break;
		break;
	case  CMD_MSG_GSHEART_KG:
		break;
	case CMD_MSG_GSHEART_LBS:
		break;
   

	default:
		break;
	}

	InvalidateRect(m_hWnd,NULL,FALSE);
}